<template>
  <div class="my-container">
    <!-- 顶部区域 -->
    <div class="top-bar">
      <van-image
        width="60"
        round
        fit="cover"
        height="60"
        :src="userInfo.photo"
      />
      <h2 class="username">
        {{ userInfo.name }}
        <br />
        <van-tag type="primary" color="#fff" text-color="#3296fa">{{
          userInfo.birthday
        }}</van-tag>
      </h2>
    </div>
    <!-- 操作连接布局 -->
    <van-row>
      <van-col span="8">
        <van-icon color="#77aaff" name="newspaper-o" /> <span>我的作品</span>
      </van-col>
      <van-col span="8">
        <van-icon color="#ff0000" name="star-o" /><span>我的收藏</span>
      </van-col>
      <van-col span="8">
        <van-icon color="#ffaa00" name="tosend" /><span>阅读历史</span>
      </van-col>
    </van-row>
    <!-- 底部的区域 -->
    <div class="bottom">
      <van-cell-group>
        <van-cell icon="edit" title="编辑资料" is-link to="/edit" />
        <van-cell icon="chat-o" title="小智同学" is-link to="/student" />
        <van-cell icon="setting-o" title="系统设置" is-link />
        <van-cell icon="warning-o" @click="logout" title="退出登录" is-link />
      </van-cell-group>
    </div>
  </div>
</template>

<script>
// import { getUserInfo } from '../../api/my.js'
import { removeToken } from '../../utils/token.js'
import { mapState } from 'vuex'
export default {
  name: 'my',
  created () {
    // getUserInfo().then(res => {
    //   console.log(res)
    //   this.userInfo = res.data.data
    // })
  },
  data () {
    return {
      // userInfo: {}
    }
  },
  computed: mapState(['userInfo']),
  methods: {
    logout () {
      this.$dialog({
        title: '那我走？',
        message: '你再想想'
      })
        .then(() => {
          // 删除token
          removeToken()
          // 删除用户信息
          // this.userInfo = {}
          this.$store.commit('setUserInfo', {})
          // 去首页
          this.$router.push({ path: '/home' })
        })
        .catch(() => {
          // on cancel
          console.log('catch')
        })
    }
  }
}
</script>

<style lang="less">
.my-container {
  .top-bar {
    height: 100px;
    background-color: #3296fa;
    display: flex;
    align-items: center;
    padding-left: 15px;
    .username {
      font-size: 14px;
      margin-left: 10px;
      color: white;
      font-weight: 400;
    }
  }
  .van-row {
    padding: 20px;
    border-bottom: 1px solid #ccc;
    .van-col {
      font-size: 12px;
      text-align: center;
      .van-icon {
        font-size: 25px;
      }
      span {
        display: block;
      }
    }
  }
}
</style>
